package org.example.physics_engine.geometry;

public class Geometry {

    //返回一个归一化向量数组，代表给定顶点的所有边的法线。
    public static final Vector2d[] getCounterClockwiseEdgeNormals(Vector2d[] vertices) {
        if (vertices == null) return null;

        int size = vertices.length;
        if (size == 0) return null;

        Vector2d[] normals = new Vector2d[size];
        for (int i = 0; i < size; i++) {
            // get the edge points
            Vector2d p1 = vertices[i];
            Vector2d p2 = (i + 1 == size) ? vertices[0] : vertices[i + 1];
            // create the edge and get its left perpedicular vector
            Vector2d n = p1.to(p2).left();
            // normalize it
            n.normalize();
            normals[i] = n;
        }

        return normals;
    }
}
